package cn.raven._05_tran;

import org.apache.rocketmq.client.producer.*;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;

public class Producer {

    public static void main(String[] args) throws Exception {
        //创建生产者
        TransactionMQProducer producer = new TransactionMQProducer("my_tran_producer_name");
        //设置nameserver
        producer.setNamesrvAddr("localhost:9876");
        //启动
        producer.start();
        //指定事务监听器
        producer.setTransactionListener(new MyTranIistener());
        //创建信息对象
        Message msg = new Message("tran", "tt", "jjking".getBytes(StandardCharsets.UTF_8));
        //发送异步消息
        TransactionSendResult result = producer.sendMessageInTransaction(msg, null);
        System.out.println(result);
        //关闭生产者
        producer.shutdown();
    }
}
